package org.kojo.tdrm.servlet.ctrl;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.kojo.tdrm.entity.UserConf;
import org.kojo.tdrm.service.UserAppService;

public class UserConfAppController extends BaseController {
	private UserAppService service;
	public UserConfAppController(){
		service = new UserAppService();
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		UserConf uc = service.findUserConf(getUserId());
		JSONObject j = new JSONObject(uc);
		setJsonResp(j.toString());
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Integer reminderTime = Integer.parseInt(req.getParameter("reminderTime"));
		UserConf uc = new UserConf();
		uc.setReminderTime(reminderTime);
		service.saveUserConf(getUserId(), uc);
		JSONObject j = new JSONObject(uc);
		setJsonResp(j.toString());
	}

}
